package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "护理项目")
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation("分页查询护理项目")
    @GetMapping
    public ResponseResult<PageResponse> getByPage(@ApiParam("护理项目名称") String name,
                                                  @ApiParam("当前页码")
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @ApiParam("每页显示条数")
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @ApiParam("状态") Integer status) {
        PageResponse page = nursingProjectService.getByPage(name, pageNum, pageSize, status);
        return success(page);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult add(@ApiParam(value = "护理数据传输对象", required = true) @RequestBody NursingProjectDto dto) {
        nursingProjectService.add(dto);
        return success();
    }


    @GetMapping("/{id}")
    @ApiOperation("根据id查询回显")
    public ResponseResult getById(@ApiParam("查询的id") @PathVariable Long id) {
        NursingProjectVo vo = nursingProjectService.getById(id);
        return success(vo);
    }

    @PutMapping
    @ApiOperation("根据id修改项目")
    public ResponseResult updateById(@RequestBody NursingProjectDto dto) {
        nursingProjectService.updateById(dto);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改状态")
    public ResponseResult updateStatus(@ApiParam("传入的id")@PathVariable long id,@ApiParam("更改的状态,0:禁用，1：启用") @PathVariable Integer status) {
        nursingProjectService.updateStatus(id,status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除项目")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingProjectService.deleteById(id);
        return success();
    }
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult getAll(){
        List<NursingProjectVo> list=nursingProjectService.list();
        return success(list);
    }
}
